class ApplicationController < ActionController::Base
  # 某些机顶盒, 无法在c层操作cookies和session

  private

  def current_user
    if cookies[:UserID]
      @current_user ||= User.find_or_create_by(name: cookies[:UserID])
    end
  end

  def exception_stb
    unless Rails.env.development?
      # 异常的盒子, 直接跳转到无法播放页面
      # 如果是订购回来的页面, cookies会被覆盖掉, 导致stb_type为空, 但是这种情况, 已经无所谓了, 说明视频一定是能够播放的, 所以才能去订购, 再回来
      stb_type = cookies[:STBType]
      # IHO-2000D 长虹IHO-2000D
      if stb_type == 'E8205' || stb_type == 'EC2108V3H_pub' || stb_type == 'IHO-2000D' || (stb_type.include? 'EC2106V1H') || (stb_type.include? 'hg650') || (stb_type.include? 'HG650')
        redirect_to page_no_valid_path
      end
    end
  end
end
